


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Dataflow Concurrency (Scala) &mdash; Akka Documentation</title>
    
    <link rel="stylesheet" href="../_static/style.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../_static/prettify.css" type="text/css" />
    <link rel="stylesheet" href="../_static/base.css" type="text/css" />
    <link rel="stylesheet" href="../_static/docs.css" type="text/css" />
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Exo:300,400,600,700" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.0.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/toc.js"></script>
    <script type="text/javascript" src="../_static/prettify.js"></script>
    <script type="text/javascript" src="../_static/highlightCode.js"></script>
    <script type="text/javascript" src="../_static/effects.core.js"></script>
    <script type="text/javascript" src="../_static/effects.highlight.js"></script>
    <script type="text/javascript" src="../_static/scrollTo.js"></script>
    <script type="text/javascript" src="../_static/contentsFix.js"></script>
    <link rel="shortcut icon" href="../_static/favicon.ico"/>
    <link rel="top" title="Akka Documentation" href="../index.html" />
    <link rel="up" title="Scala API" href="index.html" />
    <link rel="next" title="Fault Tolerance (Scala)" href="fault-tolerance.html" />
    <link rel="prev" title="Futures (Scala)" href="futures.html" /> 
  </head>
  <body>
  <div class="navbar">
    <div class="navbar-inner">
      <div class="container">
        <div class="navbar-logo">
          <a href="http://akka.io"><img src="../_static/logo-small.png" /></a>
        </div>    
        <ul class="nav">
          <li><a href="http://akka.io/docs">Documentation</a></li>
          <li><a href="http://akka.io/downloads">Download</a></li>
          <li><a href="http://groups.google.com/group/akka-user">Mailing List</a></li>
          <li><a href="http://github.com/akka/akka">Code</a></li>           
          <li><a href="http://typesafe.com/products/typesafe-subscription">Commerical Support</a></li>
        </ul>
      </div>
    </div>
  </div>
  <div class="main">
    <div class="container">
      <div class="page-title">Dataflow Concurrency (Scala)</div><div class="pdf-link"><a href="http://akka.io/docs/akka/2.0.1/Akka.pdf"><img src="../_static/pdf-icon.png" style="height: 40px;" /></a></div></div>
    <div class="main-container">
      <div class="container">
        <div class="row">
          <div class="span12">
            <ul class="breadcrumb">           
              <li>
                 <span class="divider">|</span> <a href="fault-tolerance.html">Fault Tolerance (Scala)</a> <span class="divider">»</span>
              </li>
              <li>
                <a href="../index.html">Contents</a>
              </li>
              <li>
                <span class="divider">«</span> <a href="futures.html">Futures (Scala)</a> <span class="divider">|</span>
              </li>
              <li>
                Version 2.0.1
              </li>
            </ul>         
          </div>
        </div>
        <div class="row">
          <div class="span9">
            
  <div class="section" id="dataflow-concurrency-scala">
<h1>Dataflow Concurrency (Scala)</h1>
<div class="section" id="description">
<h2>Description</h2>
<p>Akka implements <a class="reference external" href="http://www.mozart-oz.org/documentation/tutorial/node8.html#chapter.concurrency">Oz-style dataflow concurrency</a> by using a special API for <a class="reference internal" href="futures.html#futures-scala"><em>Futures (Scala)</em></a> that allows single assignment variables and multiple lightweight (event-based) processes/threads.</p>
<p>Dataflow concurrency is deterministic. This means that it will always behave the same. If you run it once and it yields output 5 then it will do that <strong>every time</strong>, run it 10 million times, same result. If it on the other hand deadlocks the first time you run it, then it will deadlock <strong>every single time</strong> you run it. Also, there is <strong>no difference</strong> between sequential code and concurrent code. These properties makes it very easy to reason about concurrency. The limitation is that the code needs to be side-effect free, e.g. deterministic. You can&#8217;t use exceptions, time, random etc., but need to treat the part of your program that uses dataflow concurrency as a pure function with input and output.</p>
<p>The best way to learn how to program with dataflow variables is to read the fantastic book <a class="reference external" href="http://www.info.ucl.ac.be/%7Epvr/book.html">Concepts, Techniques, and Models of Computer Programming</a>. By Peter Van Roy and Seif Haridi.</p>
<p>The documentation is not as complete as it should be, something we will improve shortly. For now, besides above listed resources on dataflow concurrency, I recommend you to read the documentation for the GPars implementation, which is heavily influenced by the Akka implementation:</p>
<ul class="simple">
<li><a class="reference external" href="http://gpars.codehaus.org/Dataflow">http://gpars.codehaus.org/Dataflow</a></li>
<li><a class="reference external" href="http://www.gpars.org/guide/guide/7.%20Dataflow%20Concurrency.html">http://www.gpars.org/guide/guide/7.%20Dataflow%20Concurrency.html</a></li>
</ul>
</div>
<div class="section" id="getting-started">
<h2>Getting Started</h2>
<p>Scala&#8217;s Delimited Continuations plugin is required to use the Dataflow API. To enable the plugin when using sbt, your project must inherit the <tt class="docutils literal"><span class="pre">AutoCompilerPlugins</span></tt> trait and contain a bit of configuration as is seen in this example:</p>
<div class="highlight-scala"><div class="highlight"><pre><span class="n">autoCompilerPlugins</span> <span class="o">:=</span> <span class="kc">true</span><span class="o">,</span>
<span class="n">libraryDependencies</span> <span class="o">&lt;+=</span> <span class="n">scalaVersion</span> <span class="o">{</span> <span class="n">v</span> <span class="k">=&gt;</span> <span class="n">compilerPlugin</span><span class="o">(</span><span class="s">&quot;org.scala-lang.plugins&quot;</span> <span class="o">%</span> <span class="s">&quot;continuations&quot;</span> <span class="o">%</span> <span class="o">&lt;</span><span class="n">scalaVersion</span><span class="o">&gt;)</span> <span class="o">},</span>
<span class="n">scalacOptions</span> <span class="o">+=</span> <span class="s">&quot;-P:continuations:enable&quot;</span><span class="o">,</span>
</pre></div>
</div>
</div>
<div class="section" id="dataflow-variables">
<h2>Dataflow Variables</h2>
<p>Dataflow Variable defines four different operations:</p>
<ol class="arabic simple">
<li>Define a Dataflow Variable</li>
</ol>
<div class="highlight-scala"><div class="highlight"><pre><span class="k">val</span> <span class="n">x</span> <span class="k">=</span> <span class="nc">Promise</span><span class="o">[</span><span class="kt">Int</span><span class="o">]()</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li>Wait for Dataflow Variable to be bound (must be contained within a <tt class="docutils literal"><span class="pre">Future.flow</span></tt> block as described in the next section)</li>
</ol>
<div class="highlight-scala"><div class="highlight"><pre><span class="n">x</span><span class="o">()</span>
</pre></div>
</div>
<ol class="arabic simple" start="3">
<li>Bind Dataflow Variable (must be contained within a <tt class="docutils literal"><span class="pre">Future.flow</span></tt> block as described in the next section)</li>
</ol>
<div class="highlight-scala"><div class="highlight"><pre><span class="n">x</span> <span class="o">&lt;&lt;</span> <span class="mi">3</span>
</pre></div>
</div>
<ol class="arabic simple" start="4">
<li>Bind Dataflow Variable with a Future (must be contained within a <tt class="docutils literal"><span class="pre">Future.flow</span></tt> block as described in the next section)</li>
</ol>
<div class="highlight-scala"><div class="highlight"><pre><span class="n">x</span> <span class="o">&lt;&lt;</span> <span class="n">y</span>
</pre></div>
</div>
<p>A Dataflow Variable can only be bound once. Subsequent attempts to bind the variable will be ignored.</p>
</div>
<div class="section" id="dataflow-delimiter">
<h2>Dataflow Delimiter</h2>
<p>Dataflow is implemented in Akka using Scala&#8217;s Delimited Continuations. To use the Dataflow API the code must be contained within a <tt class="docutils literal"><span class="pre">Future.flow</span></tt> block. For example:</p>
<div class="highlight-scala"><div class="highlight"><pre><span class="k">import</span> <span class="nn">Future.flow</span>
<span class="k">implicit</span> <span class="k">val</span> <span class="n">dispatcher</span> <span class="k">=</span> <span class="o">...</span>

<span class="k">val</span> <span class="n">a</span> <span class="k">=</span> <span class="nc">Future</span><span class="o">(</span> <span class="o">...</span> <span class="o">)</span>
<span class="k">val</span> <span class="n">b</span> <span class="k">=</span> <span class="nc">Future</span><span class="o">(</span> <span class="o">...</span> <span class="o">)</span>
<span class="k">val</span> <span class="n">c</span> <span class="k">=</span> <span class="nc">Promise</span><span class="o">[</span><span class="kt">Int</span><span class="o">]()</span>

<span class="n">flow</span> <span class="o">{</span>
  <span class="n">c</span> <span class="o">&lt;&lt;</span> <span class="o">(</span><span class="n">a</span><span class="o">()</span> <span class="o">+</span> <span class="n">b</span><span class="o">())</span>
<span class="o">}</span>

<span class="k">val</span> <span class="n">result</span> <span class="k">=</span> <span class="nc">Await</span><span class="o">.</span><span class="n">result</span><span class="o">(</span><span class="n">c</span><span class="o">,</span> <span class="n">timeout</span><span class="o">)</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">flow</span></tt> method also returns a <tt class="docutils literal"><span class="pre">Future</span></tt> for the result of the contained expression, so the previous example could also be written like this:</p>
<div class="highlight-scala"><div class="highlight"><pre><span class="k">import</span> <span class="nn">Future.flow</span>
<span class="k">implicit</span> <span class="k">val</span> <span class="n">dispatcher</span> <span class="k">=</span> <span class="o">...</span>

<span class="k">val</span> <span class="n">a</span> <span class="k">=</span> <span class="nc">Future</span><span class="o">(</span> <span class="o">...</span> <span class="o">)</span>
<span class="k">val</span> <span class="n">b</span> <span class="k">=</span> <span class="nc">Future</span><span class="o">(</span> <span class="o">...</span> <span class="o">)</span>

<span class="k">val</span> <span class="n">c</span> <span class="k">=</span> <span class="n">flow</span> <span class="o">{</span>
  <span class="n">a</span><span class="o">()</span> <span class="o">+</span> <span class="n">b</span><span class="o">()</span>
<span class="o">}</span>

<span class="k">val</span> <span class="n">result</span> <span class="k">=</span> <span class="nc">Await</span><span class="o">.</span><span class="n">result</span><span class="o">(</span><span class="n">c</span><span class="o">,</span> <span class="n">timeout</span><span class="o">)</span>
</pre></div>
</div>
</div>
<div class="section" id="examples">
<h2>Examples</h2>
<p>Most of these examples are taken from the <a class="reference external" href="http://en.wikipedia.org/wiki/Oz_%28programming_language%29">Oz wikipedia page</a></p>
<p>To run these examples:</p>
<ol class="arabic simple">
<li>Start REPL</li>
</ol>
<div class="highlight-scala"><div class="highlight"><pre><span class="n">$</span> <span class="n">sbt</span>
<span class="o">&gt;</span> <span class="n">project</span> <span class="n">akka</span><span class="o">-</span><span class="n">actor</span>
<span class="o">&gt;</span> <span class="n">console</span>
</pre></div>
</div>
<div class="highlight-scala"><div class="highlight"><pre><span class="nc">Welcome</span> <span class="n">to</span> <span class="nc">Scala</span> <span class="n">version</span> <span class="mf">2.9</span><span class="o">.</span><span class="mi">1</span> <span class="o">(</span><span class="nc">Java</span> <span class="nc">HotSpot</span><span class="o">(</span><span class="nc">TM</span><span class="o">)</span> <span class="mi">64</span><span class="o">-</span><span class="nc">Bit</span> <span class="nc">Server</span> <span class="nc">VM</span><span class="o">,</span> <span class="nc">Java</span> <span class="mf">1.6</span><span class="o">.</span><span class="mi">0</span><span class="n">_25</span><span class="o">).</span>
<span class="nc">Type</span> <span class="n">in</span> <span class="n">expressions</span> <span class="n">to</span> <span class="n">have</span> <span class="n">them</span> <span class="n">evaluated</span><span class="o">.</span>
<span class="nc">Type</span> <span class="k">:</span><span class="kt">help</span> <span class="kt">for</span> <span class="kt">more</span> <span class="kt">information.</span>

<span class="kt">scala&gt;</span>
</pre></div>
</div>
<p>2. Paste the examples (below) into the Scala REPL.
Note: Do not try to run the Oz version, it is only there for reference.</p>
<ol class="arabic simple" start="3">
<li>Have fun.</li>
</ol>
<div class="section" id="simple-dataflowvariable-example">
<h3>Simple DataFlowVariable example</h3>
<p>This example is from Oz wikipedia page: <a class="reference external" href="http://en.wikipedia.org/wiki/Oz_(programming_language">http://en.wikipedia.org/wiki/Oz_(programming_language</a>).
Sort of the &#8220;Hello World&#8221; of dataflow concurrency.</p>
<p>Example in Oz:</p>
<div class="highlight-ruby"><div class="highlight"><pre><span class="n">thread</span>
  <span class="n">Z</span> <span class="o">=</span> <span class="n">X</span><span class="o">+</span><span class="n">Y</span>     <span class="o">%</span> <span class="n">will</span> <span class="n">wait</span> <span class="k">until</span> <span class="n">both</span> <span class="n">X</span> <span class="ow">and</span> <span class="n">Y</span> <span class="n">are</span> <span class="n">bound</span> <span class="n">to</span> <span class="n">a</span> <span class="n">value</span><span class="o">.</span>
  <span class="p">{</span><span class="no">Browse</span> <span class="n">Z</span><span class="p">}</span>  <span class="o">%</span> <span class="n">shows</span> <span class="n">the</span> <span class="n">value</span> <span class="n">of</span> <span class="n">Z</span><span class="o">.</span>
<span class="k">end</span>
<span class="n">thread</span> <span class="n">X</span> <span class="o">=</span> <span class="mi">40</span> <span class="k">end</span>
<span class="n">thread</span> <span class="n">Y</span> <span class="o">=</span> <span class="mi">2</span> <span class="k">end</span>
</pre></div>
</div>
<p>Example in Akka:</p>
<div class="highlight-scala"><div class="highlight"><pre><span class="k">import</span> <span class="nn">akka.dispatch._</span>
<span class="k">import</span> <span class="nn">Future.flow</span>
<span class="k">implicit</span> <span class="k">val</span> <span class="n">dispatcher</span> <span class="k">=</span> <span class="o">...</span>

<span class="k">val</span> <span class="n">x</span><span class="o">,</span> <span class="n">y</span><span class="o">,</span> <span class="n">z</span> <span class="k">=</span> <span class="nc">Promise</span><span class="o">[</span><span class="kt">Int</span><span class="o">]()</span>

<span class="n">flow</span> <span class="o">{</span>
  <span class="n">z</span> <span class="o">&lt;&lt;</span> <span class="n">x</span><span class="o">()</span> <span class="o">+</span> <span class="n">y</span><span class="o">()</span>
  <span class="n">println</span><span class="o">(</span><span class="s">&quot;z = &quot;</span> <span class="o">+</span> <span class="n">z</span><span class="o">())</span>
<span class="o">}</span>
<span class="n">flow</span> <span class="o">{</span> <span class="n">x</span> <span class="o">&lt;&lt;</span> <span class="mi">40</span> <span class="o">}</span>
<span class="n">flow</span> <span class="o">{</span> <span class="n">y</span> <span class="o">&lt;&lt;</span> <span class="mi">2</span> <span class="o">}</span>
</pre></div>
</div>
</div>
<div class="section" id="example-of-using-dataflowvariable-with-recursion">
<h3>Example of using DataFlowVariable with recursion</h3>
<p>Using DataFlowVariable and recursion to calculate sum.</p>
<p>Example in Oz:</p>
<div class="highlight-ruby"><div class="highlight"><pre><span class="n">fun</span> <span class="p">{</span><span class="no">Ints</span> <span class="n">N</span> <span class="no">Max</span><span class="p">}</span>
  <span class="k">if</span> <span class="n">N</span> <span class="o">==</span> <span class="no">Max</span> <span class="k">then</span> <span class="kp">nil</span>
  <span class="k">else</span>
    <span class="p">{</span><span class="no">Delay</span> <span class="mi">1000</span><span class="p">}</span>
    <span class="n">N</span><span class="o">|</span><span class="p">{</span><span class="no">Ints</span> <span class="n">N</span><span class="o">+</span><span class="mi">1</span> <span class="no">Max</span><span class="p">}</span>
  <span class="k">end</span>
<span class="k">end</span>

<span class="n">fun</span> <span class="p">{</span><span class="no">Sum</span> <span class="n">S</span> <span class="no">Stream</span><span class="p">}</span>
  <span class="k">case</span> <span class="no">Stream</span> <span class="n">of</span> <span class="kp">nil</span> <span class="k">then</span> <span class="n">S</span>
  <span class="o">[]</span> <span class="n">H</span><span class="o">|</span><span class="n">T</span> <span class="k">then</span> <span class="n">S</span><span class="o">|</span><span class="p">{</span><span class="no">Sum</span> <span class="n">H</span><span class="o">+</span><span class="n">S</span> <span class="n">T</span><span class="p">}</span> <span class="k">end</span>
<span class="k">end</span>

<span class="n">local</span> <span class="n">X</span> <span class="n">Y</span> <span class="k">in</span>
  <span class="n">thread</span> <span class="n">X</span> <span class="o">=</span> <span class="p">{</span><span class="no">Ints</span> <span class="mi">0</span> <span class="mi">1000</span><span class="p">}</span> <span class="k">end</span>
  <span class="n">thread</span> <span class="n">Y</span> <span class="o">=</span> <span class="p">{</span><span class="no">Sum</span> <span class="mi">0</span> <span class="n">X</span><span class="p">}</span> <span class="k">end</span>
  <span class="p">{</span><span class="no">Browse</span> <span class="n">Y</span><span class="p">}</span>
<span class="k">end</span>
</pre></div>
</div>
<p>Example in Akka:</p>
<div class="highlight-scala"><div class="highlight"><pre><span class="k">import</span> <span class="nn">akka.dispatch._</span>
<span class="k">import</span> <span class="nn">Future.flow</span>
<span class="k">implicit</span> <span class="k">val</span> <span class="n">dispatcher</span> <span class="k">=</span> <span class="o">...</span>

<span class="k">def</span> <span class="n">ints</span><span class="o">(</span><span class="n">n</span><span class="k">:</span> <span class="kt">Int</span><span class="o">,</span> <span class="n">max</span><span class="k">:</span> <span class="kt">Int</span><span class="o">)</span><span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Int</span><span class="o">]</span> <span class="k">=</span> <span class="o">{</span>
  <span class="k">if</span> <span class="o">(</span><span class="n">n</span> <span class="o">==</span> <span class="n">max</span><span class="o">)</span> <span class="nc">Nil</span>
  <span class="k">else</span> <span class="n">n</span> <span class="o">::</span> <span class="n">ints</span><span class="o">(</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="o">,</span> <span class="n">max</span><span class="o">)</span>
<span class="o">}</span>

<span class="k">def</span> <span class="n">sum</span><span class="o">(</span><span class="n">s</span><span class="k">:</span> <span class="kt">Int</span><span class="o">,</span> <span class="n">stream</span><span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Int</span><span class="o">])</span><span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Int</span><span class="o">]</span> <span class="k">=</span> <span class="n">stream</span> <span class="k">match</span> <span class="o">{</span>
  <span class="k">case</span> <span class="nc">Nil</span> <span class="k">=&gt;</span> <span class="n">s</span> <span class="o">::</span> <span class="nc">Nil</span>
  <span class="k">case</span> <span class="n">h</span> <span class="o">::</span> <span class="n">t</span> <span class="k">=&gt;</span> <span class="n">s</span> <span class="o">::</span> <span class="n">sum</span><span class="o">(</span><span class="n">h</span> <span class="o">+</span> <span class="n">s</span><span class="o">,</span> <span class="n">t</span><span class="o">)</span>
<span class="o">}</span>

<span class="k">val</span> <span class="n">x</span><span class="o">,</span> <span class="n">y</span> <span class="k">=</span> <span class="nc">Promise</span><span class="o">[</span><span class="kt">List</span><span class="o">[</span><span class="kt">Int</span><span class="o">]]()</span>

<span class="n">flow</span> <span class="o">{</span> <span class="n">x</span> <span class="o">&lt;&lt;</span> <span class="n">ints</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="mi">1000</span><span class="o">)</span> <span class="o">}</span>
<span class="n">flow</span> <span class="o">{</span> <span class="n">y</span> <span class="o">&lt;&lt;</span> <span class="n">sum</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="n">x</span><span class="o">())</span> <span class="o">}</span>
<span class="n">flow</span> <span class="o">{</span> <span class="n">println</span><span class="o">(</span><span class="s">&quot;List of sums: &quot;</span> <span class="o">+</span> <span class="n">y</span><span class="o">())</span> <span class="o">}</span>
</pre></div>
</div>
</div>
<div class="section" id="example-using-concurrent-futures">
<h3>Example using concurrent Futures</h3>
<p>Shows how to have a calculation run in another thread.</p>
<p>Example in Akka:</p>
<div class="highlight-scala"><div class="highlight"><pre><span class="k">import</span> <span class="nn">akka.dispatch._</span>
<span class="k">import</span> <span class="nn">Future.flow</span>
<span class="k">implicit</span> <span class="k">val</span> <span class="n">dispatcher</span> <span class="k">=</span> <span class="o">...</span>

<span class="c1">// create four &#39;Int&#39; data flow variables</span>
<span class="k">val</span> <span class="n">x</span><span class="o">,</span> <span class="n">y</span><span class="o">,</span> <span class="n">z</span><span class="o">,</span> <span class="n">v</span> <span class="k">=</span> <span class="nc">Promise</span><span class="o">[</span><span class="kt">Int</span><span class="o">]()</span>

<span class="n">flow</span> <span class="o">{</span>
  <span class="n">println</span><span class="o">(</span><span class="s">&quot;Thread &#39;main&#39;&quot;</span><span class="o">)</span>

  <span class="n">x</span> <span class="o">&lt;&lt;</span> <span class="mi">1</span>
  <span class="n">println</span><span class="o">(</span><span class="s">&quot;&#39;x&#39; set to: &quot;</span> <span class="o">+</span> <span class="n">x</span><span class="o">())</span>

  <span class="n">println</span><span class="o">(</span><span class="s">&quot;Waiting for &#39;y&#39; to be set...&quot;</span><span class="o">)</span>

  <span class="k">if</span> <span class="o">(</span><span class="n">x</span><span class="o">()</span> <span class="o">&gt;</span> <span class="n">y</span><span class="o">())</span> <span class="o">{</span>
    <span class="n">z</span> <span class="o">&lt;&lt;</span> <span class="n">x</span>
    <span class="n">println</span><span class="o">(</span><span class="s">&quot;&#39;z&#39; set to &#39;x&#39;: &quot;</span> <span class="o">+</span> <span class="n">z</span><span class="o">())</span>
  <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
    <span class="n">z</span> <span class="o">&lt;&lt;</span> <span class="n">y</span>
    <span class="n">println</span><span class="o">(</span><span class="s">&quot;&#39;z&#39; set to &#39;y&#39;: &quot;</span> <span class="o">+</span> <span class="n">z</span><span class="o">())</span>
  <span class="o">}</span>
<span class="o">}</span>

<span class="n">flow</span> <span class="o">{</span>
  <span class="n">y</span> <span class="o">&lt;&lt;</span> <span class="nc">Future</span> <span class="o">{</span>
    <span class="n">println</span><span class="o">(</span><span class="s">&quot;Thread &#39;setY&#39;, sleeping&quot;</span><span class="o">)</span>
    <span class="nc">Thread</span><span class="o">.</span><span class="n">sleep</span><span class="o">(</span><span class="mi">2000</span><span class="o">)</span>
    <span class="mi">2</span>
  <span class="o">}</span>
  <span class="n">println</span><span class="o">(</span><span class="s">&quot;&#39;y&#39; set to: &quot;</span> <span class="o">+</span> <span class="n">y</span><span class="o">())</span>
<span class="o">}</span>

<span class="n">flow</span> <span class="o">{</span>
  <span class="n">println</span><span class="o">(</span><span class="s">&quot;Thread &#39;setV&#39;&quot;</span><span class="o">)</span>
  <span class="n">v</span> <span class="o">&lt;&lt;</span> <span class="n">y</span>
  <span class="n">println</span><span class="o">(</span><span class="s">&quot;&#39;v&#39; set to &#39;y&#39;: &quot;</span> <span class="o">+</span> <span class="n">v</span><span class="o">())</span>
<span class="o">}</span>
</pre></div>
</div>
</div>
</div>
</div>


          </div>
          <div class="span3"><p class="contents-title">Contents</p>
              <div id="scroller-anchor">
                <div id="scroller">
                  <div id="toc"></div>
                </div>
              </div></div>
        </div>
      </div>
    </div>
  </div>
  <div class="footer">
  <div class="container">
    <ul>
      <li><h5>Akka</h5></li>
      <li><a href="http://akka.io/docs">Documentation</a></li>
      <li><a href="http://akka.io/downloads">Downloads</a></li>
    </ul>
    <ul>
      <li><h5>Contribute</h5></li>
      <li><a href="http://github.com/akka/akka">Source Code</a></li>
      <li><a href="http://groups.google.com/group/akka-user">Mailing List</a></li>      
      <li><a href="http://www.assembla.com/spaces/akka/tickets">Report a Bug</a></li>      
    </ul>
    <ul>
      <li><h5>Company</h5></li>
      <li><a href="http://typesafe.com/products/typesafe-subscription">Commercial Support</a></li>
      <li><a href="http://akka.io/team">Team</a></li>
      <li><a href="mailto:info@typesafe.com">Contact</a></li>
    </ul>
    <ul>
      <li><img src="../_static/watermark.png" align="center"/></li>
    </ul>
  </div>
  <div class="container copyright">
    <p style="float: left;">
      © 2012 <a href="http://typesafe.com/">Typesafe Inc.</a> <span class="license">Akka is Open Source and available under the Apache 2 License.</span>
    </p>
    <p style="float: right; font-size: 12px;">
      Last updated: Apr 13, 2012
    </p>          
  </div>
</div>
<script type="text/javascript">
  $('#toc').toc();
</script>
  

  </body>
</html>